<script lang="tsx">
import { ref } from 'vue'
import { useRoute } from 'vue-router'
import { getLowcodeApi } from '@/api/lowcode'
import EmptyPage from './EmptyPage/EmptyPage.vue'
import { SimpleDefaultPage } from './SimpleDefaultPage'
import { PageDataProperty } from '@/components/Lowcode/src/types/Lowcode'
import { defineComponent } from 'vue'

export default defineComponent({
  components: { EmptyPage, SimpleDefaultPage },
  setup() {
    const comp = ref('empty-page')
    let route = useRoute()
    const pageConfig = ref<PageDataProperty>()
    const param = route.params.identifier as string
    getLowcodeApi(param).then((res) => {
      if (!res.data && !res.data.text) {
        throw new Error(res.code)
      }
      pageConfig.value = JSON.parse(res.data.text)
      comp.value = (pageConfig.value?.layout || 'unknown') + '-page'
    })
    return {
      comp,
      pageConfig
    }
  }
})
</script>
<template>
  <component :is="comp" :pageConfig="pageConfig" />
</template>
